"use client"; import { GameItem, Rank, RankDetail, RankReward } from "@/api/activity"; import Vip from "@/components/Vip"; import clsx from "clsx"; import React from "react"; import styles from "./page.module.scss"; interface Props { data: RankDetail; rankList: Rank[]; gamesInfo?: { count: number; list: GameItem[]; }; } const MiddleContainer: React.FC = ({ data, rankList = [], gamesInfo }) => { const headerData = React.useMemo(() => { if (!rankList?.length) return []; const res = rankList.slice(0, 3); const result: any[] = [null, null, null]; result[0] = res[1]; result[1] = res[0]; result[2] = res[2]; console.log(result); return result; }, [rankList]); const [actId, setActId] = React.useState("middleContainer"); const actIdRef = React.useRef("middleContainer"); React.useEffect(() => { watchPosition(); }, []); const watchPosition = () => { let targetId = "middleContainer"; hrefCfg.forEach((item) => { const dom = document.querySelector(`#${item.id}`); if (dom) { const rect = dom.getBoundingClientRect(); if (rect.top < item.spaceTop) { targetId = item.id; } } const stickyBox: any = document.querySelector("#stickyBox"); if (stickyBox) { const stickyRect = stickyBox.getBoundingClientRect(); if (stickyRect.top < 60) { stickyBox.style.background = "rgba(0,0,0,.7)"; } else { stickyBox.style.background = "rgba(255,255,255,0)"; } } }); if (actIdRef.current !== targetId) { } setActId(targetId); requestAnimationFrame(watchPosition); }; React.useEffect(() => { actIdRef.current = actId; }, [actId]); const moreList = React.useMemo(() => { if (!rankList?.length) return []; const res = rankList.slice(3, rankList?.length); return res; }, [rankList]); const showSelfInBottom = React.useMemo(() => { return true; // return rankList.findIndex((item) => item.rank === data.self_rank.rank) === -1; }, [rankList, data]); const hrefCfg = React.useMemo(() => { return [ { text: "Classificaçães", id: "middleContainer", spaceTop: 60, }, { text: `Jogos(${gamesInfo?.count})`, id: "jackpot", spaceTop: 100, }, { text: "Regras", id: "rankFooter", spaceTop: 60, }, ]; }, [gamesInfo]); const scrollInto = (item: any) => { const dom = document.querySelector(`#${item.id}`); // setActId(item.id); dom?.scrollIntoView({ behavior: "smooth", block: "start", }); }; return ( <> {!!headerData?.length && (
{headerData.map((item: Rank, idx) => { // const curVip = vipImagesMap.get(item?.vipLevel || 1); // console.log(123123, item); if (!item) { return
; } return (
{item && ( <> )}
); })}
{headerData.map((item: Rank, idx) => { let curReward: RankReward = {} as RankReward; if (item?.reward?.length) { curReward = item?.reward[0]; } return (
{item && ( <>
{item.nickName}
{item.score}
R${curReward?.amount || 0}
{curReward?.ratio || 0}%
)}
); })}
)} {!!moreList?.length && (
{moreList.map((item, idx) => { let curReward: RankReward = {} as RankReward; if (item?.reward?.length) { curReward = item?.reward[0]; } return (
{item.rank} {/* {idx + 4} */}
{item?.nickName}
{item.score}
R${curReward?.amount || 0}
{curReward?.ratio}%
); })} {showSelfInBottom && (
{data?.self_rank?.rank === -1 ? "-" : data?.self_rank?.rank}
{data.self_rank.nickName}
{data.self_rank.score}
R$ {data.self_rank.reward && data.self_rank.reward[0] ? data.self_rank.reward[0].amount : 0}
{data.self_rank.reward && data.self_rank.reward[0] ? data.self_rank.reward[0].ratio : 0} %
)}
)} ); }; export default MiddleContainer;